package com.hc.pingtan.controller;


import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hc.pingtan.conf.ImageReplace;
import com.hc.pingtan.model.CommonResult;
import com.hc.pingtan.model.DetailSxoGoods;
import com.hc.pingtan.model.FindSxoGoods;
import com.hc.pingtan.model.SxoGoods;
import com.hc.pingtan.service.ISxoGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品 前端控制器
 * </p>
 *
 * @author astupidcoder
 * @since 2021-11-02
 */
@Api(tags = "商城")
@RestController
@RequestMapping("/sxo-goods")
public class SxoGoodsController {
    @Resource
    private ISxoGoodsService mISxoGoodsService;
    @Resource
    private ImageReplace imageReplace;

    @ApiOperation(value = "服务商城列表", notes = "服务商城列表", httpMethod = "POST")
    @RequestMapping("findQsJobsList")
    public CommonResult<List<SxoGoods>> findSxoGoods(@RequestBody(required = false) FindSxoGoods findSxoGoods) {
        QueryWrapper<SxoGoods> wrappers = new QueryWrapper();
        if (findSxoGoods != null && StringUtils.isNotBlank(findSxoGoods.getTitle())) {
            wrappers.like("title", findSxoGoods.getTitle());
        }
        List<SxoGoods> list = mISxoGoodsService.list(wrappers);
        return CommonResult.<List<SxoGoods>>builder().result(imageReplace.shopxoImageReplace(list, new TypeReference<List<SxoGoods>>() {
        })).build();
    }


    @ApiOperation(value = "服务商城数据详情", notes = "服务商城数据详情", httpMethod = "POST")
    @RequestMapping("detailSxoGoods")
    public CommonResult<SxoGoods> detailSxoGoods(@RequestBody DetailSxoGoods detailSxoGoods) {
        QueryWrapper<SxoGoods> wrappers = new QueryWrapper();
        if (detailSxoGoods != null && StringUtils.isNotBlank(detailSxoGoods.getId())) {
            wrappers.eq("id", detailSxoGoods.getId());
        }
        SxoGoods list = mISxoGoodsService.getOne(wrappers);
        return CommonResult.<SxoGoods>builder().result(imageReplace.shopxoImageReplace(list, new TypeReference<SxoGoods>() {
        })).build();
    }
}
